package com.baizhi.service.impl;

import com.baizhi.service.UserLikedService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.HashOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
public class UserLikedServiceImpl implements UserLikedService {


    private static final Logger log = LoggerFactory.getLogger(UserLikedServiceImpl.class);
    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void userLike(Integer uid, Integer videoId) {

        /**
         * 名称
         * 索引 视频+id
         * 值为 用户id
         */
        HashOperations hashOperations = redisTemplate.opsForHash();
        hashOperations.put("video_like_id:" + videoId, "user_id:" + uid, uid);
    }

    @Override
    public void userLikeDelete(Integer uid, Integer videoId) {
        HashOperations hashOperations = redisTemplate.opsForHash();
        Long delete = hashOperations.delete("video_like_id:" + videoId, "user_id:" + uid);
        log.info("用户取消喜欢数 {}", delete);
    }

    @Override
    public void userDisLike(Integer uid, Integer videoId) {
        HashOperations hashOperations = redisTemplate.opsForHash();
        hashOperations.put("video_dislike_id:" + videoId, "user_id:" + uid, uid);
    }

    @Override
    public void userDisLikeDelete(Integer uid, Integer videoId) {
        HashOperations hashOperations = redisTemplate.opsForHash();
        Long delete = hashOperations.delete("video_dislike_id:" + videoId, "user_id:" + uid);
        log.info("用户取消不喜欢数 {}", delete);
    }


}
